package com.ticket.sass.admin.dto.input;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;

@Data
@ApiModel(description = "星期时间输入模型")
public class WeekTimeInput {
    @ApiModelProperty(value = "星期", example = "0", required = true)
    @Min(value = 0, message = "星期必须介于0到6之间")
    @Max(value = 6, message = "星期必须介于0到6之间")
    private Integer week;
    
    @Valid
    @ApiModelProperty(value = "时间段")
    private List<WeekTime> times;
    
    @Data
    @ApiModel(description = "优惠券有效时间段")
    public static class WeekTime {
        @NotBlank(message = "开始时间不能为空")
        @ApiModelProperty(value = "开始时间", example = "08:00", required = true)
        @Pattern(regexp = "([01]?[0-9]|2[0-3]):[0-5][0-9]", message = "时间格式必须为HH:mm")
        private String start;
        
        @NotBlank(message = "结束时间不能为空")
        @ApiModelProperty(value = "结束时间", example = "18:00", required = true)
        @Pattern(regexp = "([01]?[0-9]|2[0-3]):[0-5][0-9]", message = "时间格式必须为HH:mm")
        private String end;
    }
    
    public static String getString(List<WeekTimeInput.WeekTime> inputWeekTimes, Boolean available) {
        JSONArray jsonArray = new JSONArray();
        for (WeekTimeInput.WeekTime inputWeekTime : inputWeekTimes) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("start", inputWeekTime.getStart());
            jsonObject.put("end", inputWeekTime.getEnd());
            jsonObject.put("available", available); // Assuming you always set it to false
            jsonArray.add(jsonObject);
        }
        return jsonArray.toString();
    }
}

